package com.dyypdadmin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dyypdadmin.pojo.MedicalRecords;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MedicalRecordsDao extends BaseMapper<MedicalRecords> {

    @Insert("insert into medicalrecords(order_number,user_id,diagnosis_result, is_medication_required,medication_details,doctor_advice) values (#{order_number},#{user_id},#{diagnosis_result},#{is_medication_required},#{medication_details},#{doctor_advice})")
    int addMedicalRecord(
            @Param("order_number") String order_number,
            @Param("user_id") Integer user_id,
            @Param("diagnosis_result") String diagnosis_result,
            @Param("is_medication_required") Integer is_medication_required,
            @Param("medication_details") String medication_details,
            @Param("doctor_advice") String doctor_advice);
    @Select("select * from medicalrecords where user_id = #{user_id}")
    List<MedicalRecords> getByUserId(@Param("user_id") Integer user_id);

    //根据订单号查询
    @Select("select * from medicalrecords where order_number = #{order_number}")
    List<MedicalRecords> getAllMedicalRecordByOrderNumbergetAllMedicalRecord(@Param("order_number")String order_number);

    @Select("select count(*) from medicalrecords")
    int getMedicalRecordsCounts();

    //根据宠物id查询所有属于宠物的诊疗记录
    @Select("select * from medicalrecords join servicerecords s on medicalrecords.order_number = s.order_number where s.pet_id=#{pet_id} order by s.complete_time desc")
    List<MedicalRecords> getAllMedicalRecordsByPetId(@Param("pet_id")Integer pet_id);
}
